﻿// Type: FluentNHibernate.Automapping.DefaultAutomappingConfiguration
// Assembly: FluentNHibernate, Version=1.2.0.712, Culture=neutral, PublicKeyToken=8aa435e3cb308880
// Assembly location: e:\mydoc\visual studio 2010\Projects\NHibernateTest\NHibernateTest\ThirdPart\FluentNHibernate.dll

using FluentNHibernate;
using FluentNHibernate.Automapping.Alterations;
using FluentNHibernate.Automapping.Steps;
using FluentNHibernate.Conventions;
using FluentNHibernate.Mapping;
using FluentNHibernate.Utils;
using System;
using System.Collections.Generic;

namespace FluentNHibernate.Automapping
{
  public class DefaultAutomappingConfiguration : IAutomappingConfiguration
  {
    public virtual bool ShouldMap(Member member)
    {
      if (member.IsProperty)
        return member.IsPublic;
      else
        return false;
    }

    public virtual bool ShouldMap(Type type)
    {
      if (!Extensions.ClosesInterface(type, typeof (IAutoMappingOverride<>)) && !Extensions.HasInterface(type, typeof (IMappingProvider)) && !type.IsNested)
        return type.IsClass;
      else
        return false;
    }

    public virtual bool IsId(Member member)
    {
      return member.Name.Equals("id", StringComparison.InvariantCultureIgnoreCase);
    }

    public virtual Access GetAccessStrategyForReadOnlyProperty(Member member)
    {
      return MemberAccessResolver.Resolve(member);
    }

    public virtual Type GetParentSideForManyToMany(Type left, Type right)
    {
      if (left.FullName.CompareTo(right.FullName) >= 0)
        return right;
      else
        return left;
    }

    public virtual bool IsConcreteBaseType(Type type)
    {
      return false;
    }

    public virtual bool IsComponent(Type type)
    {
      return false;
    }

    public virtual string GetComponentColumnPrefix(Member member)
    {
      return member.Name;
    }

    public virtual bool IsDiscriminated(Type type)
    {
      return false;
    }

    public virtual string GetDiscriminatorColumn(Type type)
    {
      return "discriminator";
    }

    [Obsolete("Use IsDiscriminated instead.", true)]
    public SubclassStrategy GetSubclassStrategy(Type type)
    {
      throw new NotSupportedException();
    }

    public virtual bool AbstractClassIsLayerSupertype(Type type)
    {
      return true;
    }

    public virtual string SimpleTypeCollectionValueColumn(Member member)
    {
      return "Value";
    }

    public virtual bool IsVersion(Member member)
    {
      List<string> list1 = new List<string>()
      {
        "version",
        "timestamp"
      };
      List<Type> list2 = new List<Type>()
      {
        typeof (int),
        typeof (long),
        typeof (TimeSpan),
        typeof (byte[])
      };
      if (list1.Contains(member.Name.ToLowerInvariant()))
        return list2.Contains(member.PropertyType);
      else
        return false;
    }

    public virtual IEnumerable<IAutomappingStep> GetMappingSteps(AutoMapper mapper, IConventionFinder conventionFinder)
    {
      return (IEnumerable<IAutomappingStep>) new IAutomappingStep[7]
      {
        (IAutomappingStep) new IdentityStep((IAutomappingConfiguration) this),
        (IAutomappingStep) new VersionStep((IAutomappingConfiguration) this),
        (IAutomappingStep) new ComponentStep((IAutomappingConfiguration) this),
        (IAutomappingStep) new PropertyStep(conventionFinder, (IAutomappingConfiguration) this),
        (IAutomappingStep) new HasManyToManyStep((IAutomappingConfiguration) this),
        (IAutomappingStep) new ReferenceStep((IAutomappingConfiguration) this),
        (IAutomappingStep) new HasManyStep((IAutomappingConfiguration) this)
      };
    }
  }
}
